package entity;

import java.util.Date;

import client.Client;


public class OneTimeCostumerOrder {
	private String costumer_id;
	private Date leaving_hour;
	private Date entering_hour;
	private Date actual_leaving_hour;
	private String mail;
	private String car_number;
	private boolean payment_status;
	public enum oneTimeCostumerEnum {CORRECT,ID_ERROR,CAR_NUMBER_ERROR,EMAIL_ERROR,LEAVING_HOUR_ERROR};
	
	public OneTimeCostumerOrder() {
		payment_status=false;
		this.entering_hour=new Date();
		this.actual_leaving_hour=null;
	}
	
	public OneTimeCostumerOrder(String costumer_id, Date leaving_hour, String mail, String car_number) 
	{
		payment_status=false;
		this.costumer_id=costumer_id;
		this.leaving_hour=(Date) leaving_hour.clone();
		this.mail=mail;
		this.car_number=car_number;
		this.entering_hour=new Date();
		this.actual_leaving_hour=null;
	}
	
	
	public void saveToDB()
	{
		Client.saveOneTimeCostumerToDB(this);
	}
	
	public oneTimeCostumerEnum validate()
	{
		if (this.costumer_id.length() != 9)
			return oneTimeCostumerEnum.ID_ERROR;
		try{
			  Integer.parseInt(this.costumer_id);
			  // is an integer!
			} catch (NumberFormatException e) {
				return oneTimeCostumerEnum.ID_ERROR;// not an integer!
			}
		
		if (this.car_number.length() != 7)
			return oneTimeCostumerEnum.CAR_NUMBER_ERROR;
		try{
			  Integer.parseInt(this.car_number);
			  // is an integer!
			} catch (NumberFormatException e) {
				return oneTimeCostumerEnum.CAR_NUMBER_ERROR;// not an integer!
			}
		if(this.leaving_hour.compareTo(new Date())<=0)
			return oneTimeCostumerEnum.LEAVING_HOUR_ERROR;
		if(mail.indexOf('@')==-1 || mail.lastIndexOf('.')<mail.indexOf('@') || mail.startsWith("@"))
			return oneTimeCostumerEnum.EMAIL_ERROR;
		
		return oneTimeCostumerEnum.CORRECT;	
	}
	
	
	public String getCostumer_id() {
		// TODO Auto-generated method stub
		return costumer_id;
	}
	public boolean isPayment_status() {
		return payment_status;
	}
	public void setPayment_status(boolean payment_status) {
		this.payment_status = payment_status;
		Client.updateOneTimeCustomerOrder(this);
	}
	public Date getLeaving_hour() {
		return leaving_hour;
	}
	public void setLeaving_hour(Date leaving_hour) {
		this.leaving_hour = leaving_hour;
		Client.updateOneTimeCustomerOrder(this);
	}
	public String getMail() {
		return mail;
	}
	public void setMail(String mail) {
		this.mail = mail;
		Client.updateOneTimeCustomerOrder(this);
	}
	public String getCar_number() {
		return car_number;
	}
	public void setCar_number(String car_number) {
		this.car_number = car_number;
		Client.updateOneTimeCustomerOrder(this);
	}
	public String toString()
	{
		return "costumer id: " + costumer_id + "\nleaving time: " + leaving_hour + "\nmail: " + mail + "\ncar number: " + car_number;
	}

	public Date getEntering_hour() {
		return entering_hour;
	}

	public void setEntering_hour(Date entering_hour) {
		this.entering_hour = entering_hour;
		Client.updateOneTimeCustomerOrder(this);
	}

	public Date getActual_leaving_hour() {
		return actual_leaving_hour;
	}

	public void setActual_leaving_hour(Date actual_leaving_hour) {
		this.actual_leaving_hour = actual_leaving_hour;
	}

}
